home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d21
/
apishare.arc
/
SHAREB.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1988-10-22
|
3KB
|
147 lines
(****************************************************************
*
* Name: SHAREB
*
* Function: share memory/data with another process
*
* Shows how to: 1. read from and write to shared memory.
* 2. receive from another process the address of shared data.
* 3. control access to shared data via mailbox semaphore.
*
****************************************************************)
program ShareB;
uses DVAPI;
const
(* minimum API version required *)
REQUIRED = $201;
var
(* API version number *)
version : integer;
(* TFDD text file *)
tfd : text;
(* application handle of other process *)
apphana : ULONG;
(* mail-related variables *)
status : integer;
malptr : pointer;
mallng : integer;
type
(* type declarations related to shared data *)
DATATYPE = string;
DATAPTR = ^DATATYPE;
const
(* constant value to be assigned to shared memory *)
SHRCONST : DATATYPE = ' BBBBB';
var
(* pointer to pointer to shared data *)
shrptrptr : ^DATAPTR;
(* pointer to shared data *)
shrptr : DATAPTR;
(* mailbox semaphore controlling access to shared memory *)
sema : ULONG;
const
(* global name of mailbox *)
name : string = 'Shared Memory Semaphore';
procedure program_body;
begin
(* open TFDD *)
tfd_open (tfd,win_me);
(* find named mailbox semaphore *)
sema := mal_sfind (name);
(* read pointer to mailed data *)
status := mal_read (mal_me,malptr,mallng);
(* assign read pointer to a variable which is a pointer to a pointer *)
shrptrptr := malptr;
(* assign pointer to shared data by dereferencing pointer to pointer *)
shrptr := shrptrptr^;
(* get the application task handle of other process *)
apphana := mal_addr (mal_me);
(* begin critical region *)
api_beginc;
(* loop till handle of other process is no longer valid *)
while (api_isobj (apphana)) do
begin
(* lock semaphore *)
mal_lock (sema);
(* read & display current contents & address of shared data *)
writeln (tfd,shrptr^,' at ',seg (shrptr^),':',ofs (shrptr^));
(* modify contents of shared data *)
shrptr^ := SHRCONST;
(* unlock semaphore *)
mal_unlock (sema);
(* end critical region *)
api_endc;
(* begin critical region *)
api_beginc;
end;
(* close TFDD *)
tfd_close (tfd);
end;
(**********************************************************************
* main - check for DESQview present and enable required extensions.
***********************************************************************)
begin
(* initialize Pascal interfaces and get API version number *)
version := api_init;
(* if DESQview is not running or version is too low, display a message *)
if (version < REQUIRED) then
writeln ('This program requires DESQview version ',REQUIRED div 256,
'.',(REQUIRED mod 256) div 16,(REQUIRED mod 256) mod 16,' or later.')
else
begin
(* tell DESQview what extensions to enable and start application *)
api_level (REQUIRED);
program_body;
(* disable Pascal interfaces and return from program *)
api_exit;
end;
end.